package com.docios.cookbook2.ui.otherPager;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.docios.cookbook2.databinding.ActivityCommonChildBinding;

import java.util.Objects;

public class CommonChildActivity extends AppCompatActivity {
    ActivityCommonChildBinding drawerBinding;
    Fragment fragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        drawerBinding =ActivityCommonChildBinding.inflate(getLayoutInflater());
        setContentView(drawerBinding.getRoot());

        initData();

    }

    private void initData() {
        String flag=getIntent().getStringExtra("flag");
        assert flag != null;
        if (flag.equals("favorite")){
            fragment=new FavoriteFragment();
            changeFragment(fragment);
        } else if (flag.equals("home_search")) {
            fragment=new SearchFragment();
            changeFragment(fragment);
        } else if (flag.equals("classid")) {
            fragment=new SearchFragment();
            //向fragment传值
            String classid=getIntent().getStringExtra("classid");
            Bundle bundle=new Bundle();
            bundle.putString("classid",classid);
            fragment.setArguments(bundle);

            changeFragment(fragment);
        }
    }

    private void changeFragment(Fragment fragment) {
        getSupportFragmentManager()
                .beginTransaction()
                .replace(drawerBinding.fragmentFrame.getId(),fragment)
                .commit();
    }


}